package common.code;

import java.io.File;
import java.net.URISyntaxException;

/**
 * 生成唯一编号
 * @author EZreal
 *
 */
public class GetOrder {
	private static GetOrder instance = null;
	public GetOrder(){
		
	}
	public static GetOrder getInstance(){
		if(instance == null){
			synchronized(GetOrder.class){
				if(instance==null){
					instance = new GetOrder();
				}
			}
		}
		return instance;
	}

	/**
	 * 生成唯一序列号<br>
	 * 修改：支持前缀参数的序列化 update zdy 2011-10-10 <br>
	 * @param prefix - 前缀 如：KH
	 * @param num - 位数 如：3
	 * @return prefix + date(日期) + 0001(num位) -> KH20110916001
	 */
	public static String getOrderNo(String prefix,int num){
		String path = "orderNumber.dat";
		try {
			File file = new File(Thread.currentThread().getContextClassLoader().getResource("orderNumber.dat").toURI());
			if(file.exists()){
				path=file.getPath();
				//System.err.println(path);
			}
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}

		FileEveryDaySerialNumber serial = new FileEveryDaySerialNumber(prefix, num, path);
		
		return serial.getSerialNumber();
	}
	public static void main(String args[]){
//		System.out.println(GetOrder.getOrderNo("HT",3));
		String num = GetOrder.getOrderNo("KH",3);
		String num1 = GetOrder.getOrderNo("YW",3);
		System.out.println(num);
		System.out.println(num1);
	}
	
}
